package net.app.zoneland.dataway.hasor;

import net.app.zoneland.dataway.handler.DayaWayPreExecuteChainSpi;
import net.hasor.core.ApiBinder;
import net.hasor.core.AppContext;
import net.hasor.core.DimModule;
import net.hasor.dataway.spi.ApiInfo;
import net.hasor.dataway.spi.PreExecuteChainSpi;
import net.hasor.dataway.spi.ResultProcessChainSpi;
import net.hasor.db.JdbcModule;
import net.hasor.db.Level;
import net.hasor.spring.SpringModule;
import net.hasor.utils.future.BasicFuture;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.sql.DataSource;
import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName DatawayModule
 * @Deccription TODO
 * @Author DZ
 * @Date 2020/5/13 21:48
 **/
@DimModule
@Component
public class DatawayModule implements SpringModule {

    @Autowired
    private DataSource dataSource = null;

    @Autowired
    private DayaWayPreExecuteChainSpi dayaWayPreExecuteChainSpi;

    @Override
    public void loadModule(ApiBinder apiBinder) throws Throwable {
        /**
         * 1.加载数据源
         */
        apiBinder.installModule(new JdbcModule(Level.Full, this.dataSource));

        /**
         * 2.前置过滤器，可以进行校验等操作
         *   如果设置了future,该接口将直接返回future.不再继续执行.可以实现缓存.
         */
        apiBinder.bindSpiListener(PreExecuteChainSpi.class, dayaWayPreExecuteChainSpi);

        /**
         * 3.后置过滤器
         *   可以获取到返回值.对返回值统一处理
         */
        apiBinder.bindSpiListener(ResultProcessChainSpi.class, dayaWayPreExecuteChainSpi);
    }

    // 如果环境中已经存在 Hasor 上下文，那么就通过一来注入来获取
    // DatawayService dataway = appContext.getInstance(DatawayService.class);
    @Override
    public void onStart(AppContext appContext) throws Throwable {
        //
    }


}
